package com.jt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import com.jt.vo.PageResult;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 刘昱江
 * 时间 2021/2/2
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    List<User> findUserListByPage(Integer start, Integer pageSize, String username);
    @Delete("delete from user_role where id = #{id}")
    void deleteUserRole(Integer id);
    @Insert("insert into user_role(id,role_id) values(#{userId},#{roleId})")
    void saveUserRole(Integer userId, Integer roleId);
    /**
     * 基于用户名查询用户信息，此方法服务登录操作
     * @param username 这个值来自客户端用户的输入
     * @return 查询到的用户信息
     */
    @Select("select id,username,password,status " +
            "from user where username=#{username}")
    User selectUserByUsername(String username);
    /**
     * 基于用户id查询用户权限(这里比较难)
     * @param userId
     * @return
     */
    @Select("select distinct m.permission " +
            "from user_role ur join role_rights rr " +
            "on ur.role_id=rr.role_id join menus m " +
            "on rr.menus_id=m.id where ur.id=#{userId}")
    List<String> selectUserPermissions(Long userId);
}
